/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fiap.Codigo;

import br.com.fiap.Classes.Itens;
import java.util.List;
import javax.management.Query;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author rm64596
 */
public class DAOLojinha {
    
    private EntityManagerFactory emFactory;
    private EntityManager motor;
    private EntityTransaction transacao;
    
    public DAOLojinha() throws Exception
    {
		
	emFactory = Persistence.createEntityManagerFactory("CADASTRO_CONTATOS");	
		
	motor = emFactory.createEntityManager();
		
	transacao = motor.getTransaction();
		
		
    }
    
    // ---------- PESQUISAR - CONTATO
	
	public void pesquisar() throws Exception
	{
		transacao.begin();
		
		javax.persistence.Query query = motor.createQuery("select p from Contato p"); 
		
		List<Itens> listaItens = query.getResultList();
		
			System.out.println("********* Itens *********");
			
		for(Itens registro : listaItens)
		{
			
			System.out.println("Codigo : " + registro.getCodigo());
                        System.out.println("Preco : " + registro.getPreco());

		}

		transacao.commit();
		
	};
    
    
    
    
}
